﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.ServiceModel.Web;

namespace JXT.PrimaryKey.Batman.Core.WcfService
{
    public class WebHttpException : WebFaultException<WebHttpError> {
        public WebHttpErrorCode ErrorCode { get; private set; }

        public WebHttpException(string message, params object[] args)
            : this(HttpStatusCode.BadRequest, message, args) {
        }

        public WebHttpException(HttpStatusCode status, string message, params object[] args)
            : this(WebHttpErrorCode.Unknown, status, message, args) {
        }

        public WebHttpException(WebHttpErrorCode code, string message, params object[] args)
            : this(null, code, System.Net.HttpStatusCode.BadRequest, message, args) {
        }

        public WebHttpException(WebHttpErrorCode code, HttpStatusCode status, string message, params object[] args)
            : this(null, code, status, message, args) {
        }

        public WebHttpException(Exception innerException, WebHttpErrorCode code, HttpStatusCode status, string message, params object[] args)
            : base(new WebHttpError() { Code = (byte)code, Status = (int)status, Message = args == null ? message : String.Format(message, args), Args = args == null ? null : args.Select(e => e.ToString()).ToList() }, status)
        {
            ErrorCode = code;
        }
    }
}
